<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue基础</title>
    <style>
        div {
            display: inline-block;
            width: 100px;
            height: 30px;
            background-color: wheat;
            margin-bottom: 10px;
            text-align: center;
            line-height: 30px;
        }
    </style>
</head>

<body>

    <div id="app">
        <div @click="sub">-</div>
        <div>{{count}}</div>
        <div @click="add">+</div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                count: 0

            },
            methods: {
                add: function () {
                    if (this.count < 10) {
                        this.count++
                    }
                },
                // sub: function () {
                //     this.count--
                // }
                sub() {
                    if (this.count > 0) {
                        this.count--
                    }
                }
            }
        })
    </script>
</body>

</html>